<template>
    <div class="container">
      <h1>欢迎，<span>{{this.loginname}}</span></h1>
    </div>
</template>

<script>
import Schart from "vue-schart";
import bus from "../common/bus";
export default {
  name: "dashboard",
  data() {
    return {
      masterData:"",
        loginname:"",
        organizationUserId:"",
        name: localStorage.getItem("ms_username")
    };
  },
  components: {
    Schart
  },
  computed: {
    role() {
      return this.loginname === "郭跃斌" ? "超级管理员" : "普通用户";
    }
  },
  created() {
    this.changeDate();
    this.LoginName();
    this.getData();
  },
  deactivated() {
    window.removeEventListener("resize", this.renderChart);
    bus.$off("collapse", this.handleBus);
  }, 
  methods: {
    //获取机构信息
    getData() {
      var that = this;
      let organizationId = JSON.parse(localStorage.getItem("organizationIds"))[0];
      this.url = '/api/user/xzs/organization.info.get';
      this.$axios({
        url:this.url,
        method:"post",
        data:{
          organizationId:organizationId,
        },
        transformRequest: [
          function(data) {
            let ret = "";
            for (let it in data) {
              ret += encodeURIComponent(it) + "=" + encodeURIComponent(data[it]) + "&";
            }
            return ret;
          }
        ],
      }).then( res =>{  
        this.masterData = res.data.data;
        localStorage.setItem('organizationinfo',JSON.stringify(this.masterData))
      }).catch(err =>{
        console.log(err);
      })
    },
    LoginName() {
      this.url = "/api/user/xzs/organizationManager.login";
      this.$axios({
        url: this.url,
        method: "post",
        data: {}
      }).then(res => {
          this.loginname=res.data.data.name
          let organizationUserId=res.data.data.organizationUserId;
          let organizationIds=res.data.data.organizationIds;  
          localStorage.setItem("organizationIds",organizationIds)
          localStorage.setItem("organizationUserId",organizationUserId)
      }).catch(err=>{
        
      });
    },
    changeDate() {
      const now = new Date().getTime();
    },
    handleBus(msg) {
      setTimeout(() => {
        this.renderChart();
      }, 300);
    },
    renderChart() {
    }
  }
};
</script>
<style scoped>

</style>
